//
//  FifteenSpoltLightViewController.swift
//  swiftTS
//
//  Created by 航电 on 2020/4/15.
//  Copyright © 2020 航电. All rights reserved.
//  在手机spoltLight搜索关键字可搜出来

import UIKit
import CoreSpotlight

class FifteenSpoltLightViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "SpoltLight";
        self.view.backgroundColor = .white;
        // Do any additional setup after loading the view.
        self.onCreateUIForView();
        
        self.onAddData()
    }
    

    //MARK:UI
    fileprivate func onCreateUIForView() {
        let _imgView = UIImageView(frame: CGRect(x: 10, y: Tool.HEIGHT_STATUS_NAVBAR+10, width: screenMainSize.width-20, height: screenMainSize.width-20));
        _imgView.backgroundColor = .clear;
        _imgView.contentMode = .scaleAspectFit;
        _imgView.isUserInteractionEnabled = true;
        _imgView.image = UIImage(named: "picture_01");
        self.view.addSubview(_imgView);
        
        let _titleLb = UILabel(frame: CGRect(x: 0, y: screenMainSize.height-270, width: self.view.frame.width, height: 250));
        _titleLb.backgroundColor = .clear;
        _titleLb.textAlignment = .center;
        _titleLb.textColor = .lightGray;
        _titleLb.font = UIFont.systemFont(ofSize: 16);
        _titleLb.numberOfLines = 0;
        _titleLb.text = "我们在做一些app的时候经常会用到详情页，评价页，总之就是点一个按钮就展示一些信息，在做一些简单的展示或者小逻辑。一般都会presentViewController. \n 大家可以下载我的代码，看看一些跟过渡动画没有关系的设置，比如文字，和半透明背景 ，下面UIScrollView等等 ， 因为他们不是本节要介绍的重点，本节要介绍的重点是自定义过渡动画。\n首先，创建一个Single View Application，然后在Main.storyboard中定义好搞两个界面，定义好约束 。 不懂的可以下载我源码。看源码上，也可以不搞这么复杂，随便搞两个页面 练习过渡动画就行。";
        self.view.addSubview(_titleLb);
        
    }

    //MARK:Actions
    fileprivate func onAddData() {
        
        guard CSSearchableIndex.isIndexingAvailable() else {
            print("该设备不支持Spotlight搜索");
            return;
        }
        
        let itemAttr = CSSearchableItemAttributeSet(itemContentType: "img");
        itemAttr.title = "自定义拓展";
        itemAttr.keywords = ["自定义","拓展","sp"];
        itemAttr.contentDescription = "山支必须第一，宣仪第二，超越妹子第三好了";
        itemAttr.thumbnailData = UIImage.pngData(UIImage(named: "picture_01")!)();
        
        let item = CSSearchableItem(uniqueIdentifier: "fifteenSpoltlight", domainIdentifier: "aozou", attributeSet: itemAttr);
        
        CSSearchableIndex.default().indexSearchableItems([item]) { (error) in
            if error == nil {
                print("添加成功");
            } else {
                print("添加失败");
            }
        }
    }
}
